package cn.edu.scau.dormitory_management_system.module.user.service.impl;

import cn.edu.scau.dormitory_management_system.module.user.dao.UserDao;
import cn.edu.scau.dormitory_management_system.entity.UserEntity;
import cn.edu.scau.dormitory_management_system.module.user.service.UserService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {


    @Override
    public UserEntity queryByEmail(String email) {
        UserEntity userEntity = this.baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("email", email).ne("is_admin",1));
        return userEntity;
    }

    @Override
    public boolean update(UserEntity userEntity) {
        return  this.baseMapper.updateById(userEntity) > 0;
    }

    @Override
    public boolean insertUser(UserEntity user) {
        return this.baseMapper.insert(user) > 0;
    }

    @Override
    public UserEntity queryUserByRandomCode(String code) {
        return this.baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("random_code", code));
    }

    @Override
    public UserEntity queryByUserName(String email) {
        return this.baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("user_name", email));
    }
}